﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace T17Collection
{
    class Program
    {
        static void Main(string[] args)
        {
            #region 关联性泛型集合(K-v)

            #region Dictionary(哈希表)
            Dictionary<string, Product> dictProducts = new Dictionary<string, Product>();//alt+f12  速览定义
            dictProducts.Add("t1", new Product());
            dictProducts.Add("t3", new Product());
            dictProducts.Add("t2", new Product());
            //有效数据的个数
            Console.WriteLine(dictProducts .Count );
            //获取值
            Product p;
            Console.WriteLine(dictProducts .TryGetValue ("t1",out p));
            //获取键
            foreach (var key in dictProducts .Keys )
            {
                Console.Write("{0}\t",key);
            }
            Console.WriteLine();
            #endregion

            #region SortedDiction(二叉树)
            SortedDictionary<string, Product> sDictProducts = new SortedDictionary<string, Product>() ;
            sDictProducts.Add("t1", new Product());
            sDictProducts.Add("t3", new Product());
            sDictProducts.Add("t2", new Product());
            sDictProducts.Add("t4", new Product());
            Console.WriteLine(sDictProducts .Count );
            Console.WriteLine(sDictProducts .ContainsKey ("t10"));
            foreach (var key in sDictProducts .Keys )
            {
                Console.Write("{0}\t",key );
            }
            Console.WriteLine();

            #endregion

            #region SortedList(数组)
            SortedList<string, Product> sListProducts = new SortedList<string, Product>();
            sListProducts.Add("t1", new Product());
            sListProducts.Add("t3", new Product());
            sListProducts.Add("t2", new Product());
            foreach (var key in sListProducts .Keys )
            {
                Console.Write("{0}\t", key);
            }
            Console.WriteLine();
            Console.WriteLine(sListProducts .ContainsValue(null));
            #endregion

            #endregion


            #region 非关联性泛型集合

            #region List（数组）
            List<Product> lProducts = new List<Product>();
            lProducts.Add(new Product());
            Console.WriteLine(lProducts[0].GetHashCode());
            #endregion

            #region LinkedList(双向链表)
            LinkedList<Product> llProducts = new LinkedList<Product>();
            llProducts.AddLast(new Product("aa", "类型"));
            llProducts.AddFirst(new Product("bb", "类型"));
            foreach (var product in llProducts )
            {
                Console.Write("{0}\t",product.Name );
            }
            Console.WriteLine();
            #endregion

            #region HashSet(哈希表) 对象“相等”的规则（hashcode相等）
            HashSet<Product> hsProducts = new HashSet<Product> ();
            hsProducts.Add(new Product("cc", "类型"));
            hsProducts.Add(new Product("aa", "类型"));
            hsProducts.Add(new Product("aa", "类型"));
            hsProducts.Add(new Product("bb", "类型"));
            foreach (var product in hsProducts )
            {
                Console.Write("{0}\t", product.Name);
            }
            Console.WriteLine() ;

            #endregion

            #region SortedSet(二叉树)
            SortedSet<Product> ssProducts = new SortedSet<Product>();
            ssProducts.Add(new Product("cc", "类型"));
            ssProducts.Add(new Product("aa", "类型"));
            ssProducts.Add(new Product("aa", "类型"));
            ssProducts.Add(new Product("bb", "类型"));
            foreach (var product in ssProducts )
            {
                Console.Write("{0}\t", product.Name);
            }
            Console.WriteLine();

            #endregion

            #region Stack(栈)
            Stack<Product> sProducts = new Stack<Product>();
            sProducts.Push(new Product("t1", "类型"));
            sProducts.Push(new Product("t2", "类型"));
            Console.WriteLine(sProducts .Peek ().Name );
            Console.WriteLine(sProducts .Pop ().Name );
            Console.WriteLine(sProducts .Peek ().Name );

            #endregion

            #region 队列 Queue
            Queue<Product> qProducts = new Queue<Product>();
            qProducts.Enqueue(new Product("x1", "类型"));
            qProducts.Enqueue(new Product("x2", "类型"));
            Console.WriteLine(qProducts .Peek ().Name );
            Console.WriteLine(qProducts .Dequeue ().Name );
            Console.WriteLine(qProducts .Peek ().Name );

            #endregion

            #endregion

            Console.ReadKey();
        }
    }
}
